home *** CD-ROM | disk | FTP | other *** search
Java Source | 1995-12-31 | 667 b | 34 lines |
- /* try and catch example */
- class tryexample2 {
-
- public static void main(String args[]) {
-
-
- try {
- other(); // exception will be caught from
- // this call
- System.out.println("Hey it worked!");
- }
- catch(ArithmeticException e) {
- System.out.println(e.getMessage());
- }
- System.out.println("The calculations are complete!");
-
- other(); // exception will not be caught
- // system will issue an error and
- // terminate the run
- System.out.println("I never print");
-
- }
-
- static void other() {
- int a;
-
- a = 0;
- // if (a==0) throw new NullPointerException();
-
- a = 10/a;
- }
-
- }
-